<template>
	<view class="">
		<view class="ptb24" :class="{'content':type==-1 || type == -2}">
			<view class="bgf p2432 br12">
				<view class="fs30 c2a7 fw600">订单信息</view>
				<view class="mt40 flex_x">
					<view class="fs28 c9 mr30">订单编号</view>
					<view class="fs28 c3">{{order_details.sn}}</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x">
					<view class="fs28 c9 mr30">用户昵称</view>
					<view class="fs28 c3">{{order_details.address.contact}}</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x">
					<view class="fs28 c9 mr30">用户电话</view>
					<view class="fs28 c3">{{order_details.address.telephone}}</view>
				</view>
			</view>
			<view class="bgf p2432 mt24 br12">
				<view class="fs30 c2a7 fw600">用户备注</view>
				<view class="mt40 p24 fs28 c3 text_a">{{order_details.content}}</view>
			</view>
			<view class="mt24 bgf p2432 br12">
				<view class="fs30 c2a7 fw600 mb40">商品信息</view>
				<goodsList :list="goods_list" :is_serve="true" :count='count'></goodsList>
			</view>
			<view class="bgf p2432 mt24 br12" v-if="type > 0 || type == -2">
				<view class="fs30 c2a7 fw600">取货员信息</view>
				<view class="mt40 flex_x fw500">
					<view class="fs28 c9 mr60">取货员</view>
					<view class="fs28 c3">{{order_details.pick_info.nickname}}</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr30">联系方式</view>
					<view class="fs28 c3">{{order_details.pick_info.mobile}}</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr30">负责区域</view>
					<view class="fs28 c3">{{order_details.pick_info.city}}</view>
				</view>
			</view>
			<view class="bgf p2432 mt24" v-if="type > 2">
				<view class="fs30 c2a7 fw600">送回员信息</view>
				<view class="mt40 flex_x fw500">
					<view class="fs28 c9 mr60">取货员</view>
					<view class="fs28 c3">张三</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr30">联系方式</view>
					<view class="fs28 c3">18745612587</view>
				</view>
				<view class="cut_line mtb24"></view>
				<view class=" flex_x fw500">
					<view class="fs28 c9 mr40">负责区域</view>
					<view class="fs28 c3">武侯区</view>
				</view>
			</view>
		</view>

		<view class="bgf box_s flex_c" v-if="type==-1 || type == -2">
			<view class="cf fs26 bg2a7 btn1 mtb10 flex_c" @click="affirmPick">确认取货</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: '', //订单id
				sn: '', //订单编码
				order_details: '', //订单详情
				goods_list: [],
				count: 0, //数量
				type: "-1", //-1扫码分配-待取货 -2扫码分配-待送回 0待取货 1配送中 2待送回 3送回中 4已完成
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
				uni.setNavigationBarTitle({ //修改导航栏文字
					title: options.type == -1 ? '扫码取货' : '订单详情'
				})
			}
			if (options.id) {
				this.id = options.id
				this.orderInfo()
			}
			if (options.sn) {
				this.sn = options.sn
				this.orderInfo()
			}
		},
		onShow() {

		},
		methods: {
			orderInfo() { //订单详情
				this.$api.orderInfo({
					id: this.id,
					sn: this.sn
				}).then(res => {
					if (res.code == 1) {
						res.data.goods.map(item => {
							item.goods = {
								id: item.goods_id,
								image_str: item.image_str,
								price: item.goods_price,
								title: item.goods_name,
							}
							item.num = item.goods_num
						})
						this.goods_list = res.data.goods
						this.count = res.data.total
						this.order_details = res.data
					}
				})
			},
			affirmPick() { //确认取货
				if (this.type == -1) {
					this.confirmPicking()
				} else if (this.type == -2) {
					this.pickSaoReturn()
				}
			},
			confirmPicking() { //服务点 扫码取货
				this.$api.confirmPicking({
					id: this.order_details.id
				}).then(res => {
					if (res.code == 1) {
						this.$toast.toast('取货成功', () => {
							uni.navigateBack()
						})
					} else {
						uni.$u.toast(res.msg)
					}
				})
			},
			pickSaoReturn() { //清洗点扫码取货
				this.$api.pickSaoReturn({
					id: this.order_details.id
				}).then(res => {
					if (res.code == 1) {
						this.$toast.toast('取货成功', () => {
							uni.navigateBack()
						})
					} else {
						uni.$u.toast(res.msg)
					}
				})
			}
		},
	}
</script>
<style lang="scss" scoped>
	.content {
		padding-bottom: calc(150upx + env(safe-area-inset-bottom));
	}

	.text_a {
		box-sizing: border-box;
		background: #f6f6f6;
		min-height: 168upx;
	}

	.box_s {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		box-shadow: 0px -1px 0px 0px #E6E6E6;
		padding-bottom: calc(env(safe-area-inset-bottom));

		.btn1 {
			width: 687upx;
			height: 80upx;
			border-radius: 40upx;
		}
	}
</style>
